import path from 'node:path'
import { defineConfig } from 'vite'
import Uni from '@dcloudio/vite-plugin-uni'
import UniHelperManifest from '@uni-helper/vite-plugin-uni-manifest'
import UniHelperPages from '@uni-helper/vite-plugin-uni-pages'
import UniHelperComponents from '@uni-helper/vite-plugin-uni-components'
import { AnoResolver } from 'ano-ui'
import AutoImport from 'unplugin-auto-import/vite'
import UnoCSS from 'unocss/vite'

// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      '@/': `${path.resolve(__dirname, 'src')}/`,
    },
  },
  build: {
    target: 'es6',
    cssTarget: 'chrome61', // https://cn.vitejs.dev/config/build-options.html#build-csstarget
  },
  optimizeDeps: {
    exclude: ['vue-demi'],
  },
  
  plugins: [
    // https://github.com/uni-helper/vite-plugin-uni-manifest
    UniHelperManifest(),
    // https://github.com/uni-helper/vite-plugin-uni-pages
    UniHelperPages({
      subPackages: ['src/pages-square', 'src/pages-health', 'src/pages-mine', 'src/pages-shop', 'src/pages-tea'],
    }),
    // https://github.com/uni-helper/vite-plugin-uni-components
    UniHelperComponents({
      resolvers: [AnoResolver()],
      dts: 'src/components.d.ts',
      directoryAsNamespace: true,
    }),
    Uni({
      vueOptions: {
        reactivityTransform: true,
      },
    }),
    // https://github.com/antfu/unplugin-auto-import
    AutoImport({
      include: [
        /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
        /\.vue$/, /\.vue\?vue/, // .vue
      ],
      imports: ['vue', 'uni-app', 'pinia',
        {
          '@vueuse/core': ['useTimeout', 'useTimeoutFn', 'useTimestamp',
            'useInterval', 'useIntervalFn', 'until', 'watchArray', 'watchAtMost', 'watchDebounced',
            'watchDeep', 'watchIgnorable', 'watchImmediate', 'watchOnce', 'watchPausable', 'watchThrottled',
            'watchTriggerable', 'watchWithFilter', 'useArrayDifference', 'useArrayEvery', 'useArrayFilter',
            'useArrayFind', 'useArrayFindIndex', 'useArrayFindLast', 'useArrayIncludes', 'useArrayJoin', 'useArrayMap',
            'useArrayReduce', 'useArraySome', 'useArrayUnique', 'useSorted', 'useDateFormat', 'useTimeAgo',
            'useBase64', 'useConfirmDialog', 'useCounter', 'useCycleList', 'useDebounceFn',
            'useMemoize', 'useThrottleFn', 'useTimeoutPoll', 'useToggle',
          ],
          '@uni-helper/uni-use': ['useImmer', 'usePage', 'usePages', 'useRoute', 'useRouter', 'useActionSheet', 'useClipboardData',
            'tryOnLoad', 'tryOnUnload', 'tryOnReady', 'tryOnHide', 'tryOnInit', 'tryOnInit', 'tryOnShow', 'useScanCode',
            'useInterceptor', 'usePreferredDark', 'usePreferredLanguage', 'useRequest', 'useUploadFile', 'useDownloadFile',
            'useNetwork', 'useModal', 'useOnline', 'usePrevRoute', 'usePrevRoute', 'useProvider', 'useLoading',
            'useScanCode', 'useScanCode', 'useStorageAsync', 'useToast', 'useVisible'],
          '@uni-helper/uni-promises': ['chooseAddress', 'chooseFile', 'chooseImage', 'chooseInvoice', 'chooseInvoiceTitle',
            'chooseLocation', 'chooseMedia', 'chooseMessageFile', 'chooseVideo', 'clearStorage', 'request', 'login',
            'uploadFile', 'downloadFile', 'requestPayment'],
        }],
      dts: 'src/auto-imports.d.ts',
      dirs: ['src/composables', 'src/stores', 'src/utils'],
      vueTemplate: true,
    }),
    // https://github.com/antfu/unocss
    // see unocss.config.ts for config
    UnoCSS(),
  ],
})
function UniPages(arg0: { debug: boolean; subPackages: string[] }): import('vite').PluginOption
{
  throw new Error('Function not implemented.')
}

